<template>
	<view class="">
		<view class="" v-if="is_agreement">
			<zh-button openType="getPhoneNumber" @getphone='getphone'>
				<slot />
			</zh-button>
		</view>
		<view class="" v-else @click="getWxLogin">
			<slot />
		</view>
		
		<!-- 使用
		 import loginBtn from '@/components/loginBtn/loginBtn'
		 components: {	loginBtn },
		 <loginBtn></loginBtn>
		 -->
	</view>
</template>

<script>
	export default {
		props: {
			is_agreement: {
				default: true,
			}
		},
		components: {},
		data() {
			return {

			}
		},
		onLoad() {

		},
		onShow() {

		},
		methods: {
			getWxLogin() {
				if (!this.is_agreement) {
					uni.$u.toast('请先阅读并勾选协议')
				}
			},
			getphone(e) { //微信一键登录
				uni.login({
					provider: 'weixin',
					success: loginRes => {
						this.$api.login({
							code: loginRes.code,
							codes: e,
							// pid: this.pid
						}).then(res => {
							if (res.code == 200) {
								this.$store.commit('saveToken', res.data.accessToken)
								this.getUserInfo()
								// if (getCurrentPages().length > 1) {
								// 	uni.navigateBack();
								// } else {
								// 	// 需要判断是什么角色
								// 	uni.switchTab({
								// 		url: '/pages/my/my'
								// 	});
								// }
								this.$store.commit('delPid')
								this.$emit('loginSucceed')
							} else {
								uni.$u.toast(res.msg)
							}

						})
					}
				});
			},
		},
		computed: {

		},
		watch: {

		}
	}
</script>

<style lang="scss" scoped>

</style>